<?php

namespace App\Http\Models\user;

use Illuminate\Foundation\Http\FormRequest;

class UserFrom extends FormRequest
{

    public function authorize() {
        return true;
    }

    public function rules() {
        $id = $this->route("user");
        if ($id) {
            $id = decryptUrl($id);
        }
        //如果修改的时候就不用验证为空了
        $password = "";
        if ($this->route()->methods()[0] != "PUT") {
            $password = "required";
        }
        return [
            'name' => 'required|max:16',
            'username' => 'required|max:15|unique:users,username,'.$id,
            'level' => 'required|max:20',
            'phone' => 'required|integer|unique:users,phone,' . $id,
            'images' => 'required',
            'password' => "$password"
        ];
    }

    public function messages() {
        return [
            'name.required' => "姓名不能为空",
            'name.max' => "姓名不能超过16个字符",
            'level.required' => '请输入教练等级',
            'level.max' => '教练等级不能超过20个字符',
            'username.required' => '用户名不能为空',
            'username.unique' => '用户已存在',
            'username.max' => '用户名不能超过15个字符',
            'phone.required' => '手机号不能为空',
            'phone.unique' => '手机号已存在',
            'phone.integer' => '请输入正确的手机号',
            'password.required' => '密码不能为空',
            'password.max' => '密码不能超过20个字符',
            'images.required' => '头像不能为空'
        ];
    }

}
